//
//  ViewController.m
//  qq聊天消息界面3-8
//
//  Created by yb on 16/3/8.
//  Copyright © 2016年 yb. All rights reserved.
//

#import "ViewController.h"
#import "QQliaotianMessage.h"
@interface ViewController ()<UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (nonatomic,strong) NSArray *message;

@end

@implementation ViewController

- (NSArray *)message
{
    if (_message == nil) {
        //读取
        NSString *plist = [[NSBundle mainBundle] pathForResource:@"message.plist" ofType:nil];
        //加载
        NSArray *array = [[NSArray alloc]initWithContentsOfFile:plist];
        //封装数据模型
        NSMutableArray *mutable = [NSMutableArray array];
        for (NSDictionary *dict in array) {
            QQliaotianMessage *qqMessage = [QQliaotianMessage messageWithDict:dict];
            [mutable addObject:qqMessage];
        }
        _message = mutable;
    }
    return _message;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    self.tableView.dataSource = self;
    
    
    
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    //return 3;
    //QQliaotianMessage *messag = self.message[section];
    return  self.message.count;
    
}

- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
    //cell.textLabel.text = @"您好！今天下雨了吗？";
    QQliaotianMessage *qqmessage = self.message [indexPath.row];
    cell.imageView.image = [UIImage imageNamed:qqmessage.hearImage];
    cell.textLabel.text = qqmessage.message;
    
    return cell;
}


















- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
